package io.xxx.omni.oss.custom

import com.google.gson.JsonObject
import io.xxx.omni.oss.common.format
import io.xxx.omni.oss.core.PageSynchronizer
import java.util.*

/**
 * 小红书
 */
// https://school.xiaohongshu.com/en/open/
abstract class XhsSynchronizer : PageSynchronizer<JsonObject>() {

    override fun getCount(context: Context, response: JsonObject): Int {
        return response["total"].asInt
    }

    protected open fun buildRequest(context: Context, pageNo: Int): Map<String, Any> {
        val (startTime, endTime) = context
        return TreeMap(
            mapOf(
                "request" to mapOf(
                    "timeType" to 2,
                    "startTime" to startTime.format(),
                    "endTime" to endTime.format(),
                    "pageSize" to pageSize,
                    "pageNo" to pageNo,
                )
            )
        )
    }
}